package cn.meebook.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.springframework.data.annotation.CreatedDate;

/**
 * 一本书籍材料的实例，通常一本指纸质书实体，或一个电子书文件。
 * 
 * @author 王帆
 *
 */
@Entity
public class BookInstance implements Serializable {

	private static final long serialVersionUID = 551747756028584912L;
	
	@Id
    @GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;
	
	@ManyToOne
	private Book book;
	
	@ManyToOne
	private Meeker donator;
	
	@ManyToOne
	private Circle circle;
	
	@CreatedDate
	private Date donateDate;
	
	@Column(length = 100)
	private String description;
	
	protected BookInstance() {
		
	}
	
	public BookInstance(Book book, Meeker donator) {
		this.book = book;
		this.donator = donator;
		this.donateDate = new Date();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public Meeker getDonator() {
		return donator;
	}

	public void setDonator(Meeker donator) {
		this.donator = donator;
	}

	public Date getDonateDate() {
		return donateDate;
	}

	public void setDonateDate(Date donateDate) {
		this.donateDate = donateDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Circle getCircle() {
		return circle;
	}

	public void setCircle(Circle circle) {
		this.circle = circle;
	}

	@Override
	public String toString() {
		return "BookInstance [id=" + id + ", donator=" + donator
				+ ", donateDate=" + donateDate + ", circle=" + circle.getName() + "]";
	}

}
